//
// Created by bleedingfight on 2020/6/28.
//
#include "duplicate.h"

int duplicate(std::vector<int>& nums) {
    int length = nums.size();
    for (int i = 0; i < length; i++) {
        while (nums[i] != i) {
            if(nums[i]==nums[nums[i]])
                return nums[i];
            std::swap(nums[i], nums[nums[i]]);
        }
    }
    return -1;
}
